package ink.xiaobaibai.token;

import org.springframework.security.authentication.AbstractAuthenticationToken;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

/**
 * @description: 用户密码登录身份令牌
 * @author: 小白白
 * @create: 2021-05-12
 **/

public class MyUsernamePasswordAuthenticationToken extends AbstractAuthenticationToken {

    private static final long serialVersionUID = 521L;
    private String username;
    private String password;
    private String uuid;
    private String verificationCode;
    private Integer userId;

    public MyUsernamePasswordAuthenticationToken(String username, String password, String uuid, String verificationCode) {
        super(null);
        this.username = username;
        this.password = password;
        this.uuid = uuid;
        this.verificationCode = verificationCode;
    }

    private MyUsernamePasswordAuthenticationToken(String username, Collection<? extends GrantedAuthority> authorities, Integer userId) {
        super(authorities);
        this.username = username;
        this.userId = userId;
    }

    public MyUsernamePasswordAuthenticationToken getThisOkAuthenticationToken(Collection<? extends GrantedAuthority> authorities, Integer userId) {
        return new MyUsernamePasswordAuthenticationToken(this.username, authorities, userId);
    }

    public Integer getUserId() {
        return this.userId;
    }

    @Override
    public Object getCredentials() {
        return this.username;
    }

    @Override
    public Object getPrincipal() {
        return this.password;
    }

    public String getUsername() {
        return this.username;
    }

    public String getPassword() {
        return this.password;
    }

    public String getUuid() {
        return this.uuid;
    }

    public String getVerificationCode() {
        return this.verificationCode;
    }

}
